Use workspaces during `cargo install`
authorAlex Crichton <alex@alexcrichton.com>
Fri, 30 Sep 2016 20:16:38 +0000 (13:16 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 30 Sep 2016 20:16:38 +0000 (13:16 -0700)
Prevent lock files from oscillating.

Closes #3133

src/cargo/ops/cargo_install.rs
tests/install.rs

index d25bf11ba180ec696584fc52fe401c69c3e61745..616c7b351868020f2b6975175b00c4c44466af6f 100644 (file)
@@ -90,7 +90,10 @@ pub fn install(root: Option<&str>,
         Some(Filesystem::new(config.cwd().join("target-install")))
     };
 
-    let ws = try!(Workspace::one(pkg, config, overidden_target_dir));
+    let ws = match overidden_target_dir {
+        Some(dir) => try!(Workspace::one(pkg, config, Some(dir))),
+        None => try!(Workspace::new(pkg.manifest_path(), config)),
+    };
     let pkg = try!(ws.current());
 
     // Preflight checks to check up front whether we'll overwrite something.
index 5a9182a32429f7c6fa3d2e2b0b71d1ade0ca4735..6d064703fe22fec66f57f451a4a28f23eae5e853 100644 (file)
@@ -793,3 +793,36 @@ fn readonly_dir() {
                 execs().with_status(0));
     assert_that(cargo_home(), has_installed_exe("foo"));
 }
+
+#[test]
+fn use_path_workspace() {
+    Package::new("foo", "1.0.0").publish();
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.1.0"
+            authors = []
+
+            [workspace]
+            members = ["baz"]
+        "#)
+        .file("src/main.rs", "fn main() {}")
+        .file("baz/Cargo.toml", r#"
+            [package]
+            name = "baz"
+            version = "0.1.0"
+            authors = []
+
+            [dependencies]
+            foo = "1"
+        "#)
+        .file("baz/src/lib.rs", "");
+    p.build();
+
+    assert_that(p.cargo("build"), execs().with_status(0));
+    let lock = p.read_lockfile();
+    assert_that(p.cargo("install"), execs().with_status(0));
+    let lock2 = p.read_lockfile();
+    assert!(lock == lock2, "different lockfiles");
+}